package monster.com.cvh.util;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.util.Log;

import monster.com.cvh.application.TinkerApplicationLike;

/**
 * @author: pengguanming
 * @data: 2018/5/7
 * @function:检查网络工具类
 */
public class CheckNetUtils {
    private static final String TAG = "CheckNetUtils";
    //检测当前的网络状态

    public static boolean checkState_21(){
        //步骤1：通过Context.getSystemService(Context.CONNECTIVITY_SERVICE)获得ConnectivityManager对象
        ConnectivityManager connMgr = (ConnectivityManager) TinkerApplicationLike.getContext().getSystemService(Context.CONNECTIVITY_SERVICE);

        //步骤2：获取ConnectivityManager对象对应的NetworkInfo对象
        //NetworkInfo对象包含网络连接的所有信息
        //步骤3：根据需要取出网络连接信息
        //获取WIFI连接的信息
        assert connMgr != null;
        NetworkInfo networkInfo = connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
        Boolean isWifiConn = networkInfo.isConnected();

        //获取移动数据连接的信息
        networkInfo = connMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
        Boolean isMobileConn = networkInfo.isConnected();
        Log.e(TAG, "checkState_21: Wifi是否连接:" + isWifiConn +";移动数据是否连接:" + isMobileConn);
        return isMobileConn||isWifiConn;
    }

}
